using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Member_Shop_TryManagement : Member, IRequiresSessionState
{
	protected Literal TeamBuyTitle;
	protected Repeater Repeater1;
	protected Label lbPage;
	protected Button AllSelect;
	protected Button NotSelect;
	protected Button ButRecommend;
	protected Button CanelRecommend;
	protected Button ButDel;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			this.BindTryProduct();
		}
	}
	public void BindTryProduct()
	{
		CurrPageLinks currPageLinks = new CurrPageLinks();
		int num = 1;
		if (base.Request.QueryString["pageindex"] != null)
		{
			if (base.Request.QueryString["pageindex"].ToString() != "")
			{
				try
				{
					num = int.Parse(base.Request.QueryString["pageindex"].ToString());
				}
				catch (Exception ex)
				{
					ex.WriteErrorLog(new string[]
					{
						"正常操作"
					});
					num = 1;
				}
			}
		}
		int pCount = this.conn.ExecuteCount("select count(*) from HLShop_TryProduct where SalerID=" + base.user.UserID);
		int num2 = (num - 1) * 16;
		DataTable dataTable = this.conn.GetDataTable(string.Concat(new object[]
		{
			"select top 16 * from HLShop_TryProduct where TryID not in(select top ",
			num2,
			" TryID from HLShop_TryProduct where SalerID=",
			base.user.UserID,
			" order by CreateTime Desc) and SalerID=",
			base.user.UserID,
			" order by CreateTime Desc"
		}));
		this.Repeater1.DataSource = dataTable;
		this.Repeater1.DataBind();
		this.lbPage.Text = currPageLinks.CurrPageLink(num, 16, pCount, "个商品", "/Member/Shop_TryManagement.aspx?pageindex");
	}
	public string CountPeopleNum(string ProductID)
	{
		return this.conn.ExecuteCount("select count(*) from HLShop_TryAppcation where ProductID=" + int.Parse(ProductID)).ToString();
	}
	protected void lbtDel_Click(object sender, EventArgs e)
	{
		LinkButton linkButton = sender as LinkButton;
		RepeaterItem repeaterItem = linkButton.Parent as RepeaterItem;
		HiddenField hiddenField = repeaterItem.FindControl("HiddenID") as HiddenField;
		try
		{
			this.conn.Execute("delete HLShop_TryProduct where TryID=" + int.Parse(hiddenField.Value));
			this.conn.Execute("delete HLShop_TryAppcation where ProductID=" + int.Parse(hiddenField.Value));
		}
		catch (Exception ex)
		{
			ex.WriteErrorLog(new string[]
			{
				"正常操作"
			});
			this.Page.ClientScript.RegisterStartupScript(base.GetType(), "Test", "<script>alert('删除失败，请联系管理员!');</script>");
		}
		this.BindTryProduct();
	}
	protected void AllSelect_Click(object sender, EventArgs e)
	{
		for (int i = 0; i < this.Repeater1.Items.Count; i++)
		{
			CheckBox checkBox = (CheckBox)this.Repeater1.Items[i].FindControl("CheckBox1");
			checkBox.Checked = true;
		}
	}
	protected void NotSelect_Click(object sender, EventArgs e)
	{
		for (int i = 0; i < this.Repeater1.Items.Count; i++)
		{
			CheckBox checkBox = (CheckBox)this.Repeater1.Items[i].FindControl("CheckBox1");
			checkBox.Checked = false;
		}
	}
	protected void ButRecommend_Click(object sender, EventArgs e)
	{
		int num = 0;
		string text = "";
		for (int i = 0; i < this.Repeater1.Items.Count; i++)
		{
			CheckBox checkBox = (CheckBox)this.Repeater1.Items[i].FindControl("CheckBox1");
			HiddenField hiddenField = (HiddenField)this.Repeater1.Items[i].FindControl("HiddenID");
			if (checkBox.Checked)
			{
				text = text + hiddenField.Value + ",";
			}
		}
		try
		{
			num = this.conn.Execute("Update HLShop_TryProduct set IsElite=1 where TryID in(" + text.Substring(0, text.Length - 1) + ")");
		}
		catch (Exception ex)
		{
			ex.WriteErrorLog(new string[]
			{
				"正常操作"
			});
			num = 0;
		}
		if (num > 0)
		{
			this.BindTryProduct();
		}
	}
	protected void CanelRecommend_Click(object sender, EventArgs e)
	{
		int num = 0;
		string text = "";
		for (int i = 0; i < this.Repeater1.Items.Count; i++)
		{
			CheckBox checkBox = (CheckBox)this.Repeater1.Items[i].FindControl("CheckBox1");
			HiddenField hiddenField = (HiddenField)this.Repeater1.Items[i].FindControl("HiddenID");
			if (checkBox.Checked)
			{
				text = text + hiddenField.Value + ",";
			}
		}
		try
		{
			num = this.conn.Execute("Update HLShop_TryProduct set IsElite=0 where TryID in(" + text.Substring(0, text.Length - 1) + ")");
		}
		catch (Exception ex)
		{
			ex.WriteErrorLog(new string[]
			{
				"正常操作"
			});
			num = 0;
		}
		if (num > 0)
		{
			this.BindTryProduct();
		}
	}
	protected void lbtElite_Click(object sender, EventArgs e)
	{
		int num = 0;
		LinkButton linkButton = sender as LinkButton;
		RepeaterItem repeaterItem = linkButton.Parent as RepeaterItem;
		HiddenField hiddenField = repeaterItem.FindControl("HiddenID") as HiddenField;
		LinkButton linkButton2 = repeaterItem.FindControl("lbtElite") as LinkButton;
		if (linkButton2.Text == "推荐")
		{
			try
			{
				num = this.conn.Execute("Update HLShop_TryProduct set IsElite=1 where TryID=" + int.Parse(hiddenField.Value));
			}
			catch (Exception ex)
			{
				ex.WriteErrorLog(new string[]
				{
					"正常操作"
				});
				num = 0;
			}
		}
		else
		{
			try
			{
				num = this.conn.Execute("Update HLShop_TryProduct set IsElite=0 where TryID=" + int.Parse(hiddenField.Value));
			}
			catch (Exception ex)
			{
				ex.WriteErrorLog(new string[]
				{
					"正常操作"
				});
				num = 0;
			}
		}
		if (num > 0)
		{
			this.BindTryProduct();
		}
	}
	protected void ButDel_Click(object sender, EventArgs e)
	{
		int num = 0;
		string text = "";
		for (int i = 0; i < this.Repeater1.Items.Count; i++)
		{
			CheckBox checkBox = (CheckBox)this.Repeater1.Items[i].FindControl("CheckBox1");
			HiddenField hiddenField = (HiddenField)this.Repeater1.Items[i].FindControl("HiddenID");
			if (checkBox.Checked)
			{
				text = text + hiddenField.Value + ",";
			}
		}
		try
		{
			num = this.conn.Execute("delete HLShop_TryProduct where TryID in(" + text.Substring(0, text.Length - 1) + ")");
		}
		catch (Exception ex)
		{
			ex.WriteErrorLog(new string[]
			{
				"正常操作"
			});
			num = 0;
		}
		if (num > 0)
		{
			this.BindTryProduct();
		}
	}
	public string IsElite(int TryID)
	{
		string result = "推荐";
		if (this.conn.ExecuteCount("select count(*) from HLShop_TryProduct where IsElite=1 and TryID=" + TryID) > 0)
		{
			result = "取消推荐";
		}
		return result;
	}
}
